package main
{
	import code.analyze.ConfigAnalyze;
	import code.consts.ConfigConst;
	
	import com.darwin.darwinDll.Dll;
	import com.darwin.darwinMVC.core.ControllerList;
	import com.darwin.darwinMVC.mvc.Controller;
	
	import flash.utils.describeType;
	
	import module.building.controller.BuildingController;
	import module.edittroop.EditTroopController;
	import module.keyBoard.KeyBoardController;
	import module.main.MainController;
	import module.scene.FogManager;
	import module.scene.SceneController;
	import module.shop.ShopController;
	
	/**
	 * 游戏中所有控制类列表，所有的控制器会在这里标记
	 * @author lipi
	 */
	public class AppControllerList extends ControllerList
	{
		public function AppControllerList()
		{
			if(_instance == null)
			{
				super();
				_instance = this;
			}
			else{throw new Error("实例化单例类出错-AppControlerList");}
		}
		
		private static var _instance:AppControllerList;
		
		public static function getInstance():AppControllerList
		{
			if(_instance == null)
				_instance = new AppControllerList();
			
			return _instance;
		}
		
		public function start():void
		{
			setConfigList();
			var $xml:XML = describeType(this);
			var $variable:XMLList = $xml.variable;
			
			for each(var item:XML in $variable)
			{
				var $name:String = item.@name;
				var $control:Controller = this[$name] as Controller;
				if($control != null)
				{
					$control.start();
				}
			}
		}
		
		public function get appCommonView():AppCommonView
		{
			return _context.commonView as AppCommonView;
		}
		
		public function get appCommonData():AppCommonData
		{
			return _context.commonData as AppCommonData;
		}
		
		
		
		
		/**
		 * 设置配置文件列表。setConfigList方法将从Dll取出对应的配置表并将它赋值给AppDataSource
		 * @param configList
		 */
		public function setConfigList():void
		{
			var configList:Array = ConfigConst.configList;
			for(var i:int = 0;i<configList.length;i++)
			{
				var $name:String = configList[i];
				var $analyzedData:* = ConfigAnalyze.analyze($name);//解析后的数据
				var $originalData:* = Dll.getInstance().getSynPreloadRes($name);//原始数据
				_context.dataSource.setData($name,$analyzedData);
				_context.dataSource.setData($name + "_org",$originalData);
			}
		}
		
		
//		//////////////////////////////////////////////////////////////////////////////////
		
		/**
		 *	主控制器 
		 */
		public var mainController:MainController = new MainController();
		
		/**
		 *	场景控制器 
		 */
		public var sceneController:SceneController = new SceneController();
		
		/**
		 * 建筑控制器 
		 */
		public var buildController:BuildingController = new BuildingController();
		/**
		 * 控制器 
		 */
		public var editTroopController:EditTroopController = new EditTroopController();
		

		/**
		 *	快捷键控制器 
		 */
		public var keyBoardController:KeyBoardController = new KeyBoardController();
		/**
		 *商店控制器 
		 */		
		public var shopController:ShopController = new ShopController();
	}
}